<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改医护信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-nurse-edit" th:object="${nurse}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">护士姓名：</label>
                    <div class="col-sm-8">
                        <input name="nurseName" th:field="*{nurseName}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">护士年龄：</label>
                    <div class="col-sm-8">
                        <input name="nurseAge" th:field="*{nurseAge}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">性别：</label>
                <div class="col-sm-8">
                    <label class="radio-inline">
                        <input type="radio" name="nurseSex"  value="0" th:field="*{nurseSex}"/> 女
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="nurseSex" value="1" th:field="*{nurseSex}"/> 男
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">职称：</label>
                <div class="col-sm-8">
                    <label class="radio-inline">
                        <input type="radio" name="nurseProfesssional" value="0" th:field="*{nurseProfesssional}"/> 随房护士
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="nurseProfesssional" value="1" th:field="*{nurseProfesssional}"/> 初级看护
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="nurseProfesssional" value="2" th:field="*{nurseProfesssional}"/> 高级看护
                    </label>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">责任房间：</label>
                    <div class="col-sm-8">
                        <select name="chargeRoom" id="roomSelect" class="form-control" required>
                            <!-- 分类选项将通过 JavaScript 动态填充 -->
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">护士手机：</label>
                    <div class="col-sm-8">
                        <input name="nursePhone" th:field="*{nursePhone}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/nurse";
        var roomUrl = ctx + "system/room/list";
        $(document).ready(function() {
            loadRooms();
            $("#form-nurse-edit").validate({
                focusCleanup: true
            });
        });
        function loadRooms() {
            $.ajax({
                url: roomUrl,
                type: 'POST',
                dataType: 'json',
                success: function(data) {

                    var $roomSelect = $('#roomSelect');
                    console.log($roomSelect);
                    $roomSelect.empty(); // 清空现有选项
                    if (data && data.rows && Array.isArray(data.rows)) {
                        data.rows.forEach(function(room) {
                            var option = $('<option></option>')
                                .attr('value', room.id)
                                .text(room.roomNumber);
                            $roomSelect.append(option);
                        });
                    }
                },
                error: function(xhr, status, error) {
                    console.error('加载分类数据失败:', error);
                }
            });
        }
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-nurse-edit').serialize());
            }
        }
    </script>
</body>
</html>